package com.dmm.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dmm.user.entity.Userinfo;
import com.dmm.user.mapper.UserinfoMapper;
import com.dmm.user.service.UserinfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author com/dmm
 * @since 2023-04-02
 */
@Service
public class UserinfoServiceImpl extends ServiceImpl<UserinfoMapper, Userinfo> implements UserinfoService {

    @Resource
    UserinfoMapper userinfoMapper;

    //根据邮箱查询用户信息
    @Override
    public Userinfo getUserinfo(String token) {
        System.out.println(token);
        QueryWrapper<Userinfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("email",token);
        System.out.println(queryWrapper);
        Userinfo userinfo = userinfoMapper.selectOne(queryWrapper);
        return userinfo;
    }

    //根据邮箱添加用户信息
    @Override
    public boolean saveUserinfo(String email) {
        QueryWrapper<Userinfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("email",email);
        Userinfo userinfo=new Userinfo();
        userinfo.setEmail(email);
        int insert = userinfoMapper.insert(userinfo);

        if(insert==1){
            return false;
        }
        return true;
    }
}
